package com.yidin.lsc;

import android.app.Activity;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.telephony.SmsMessage;
import android.view.View;
import android.view.ViewGroup;

public class ViewPagerAdapter extends PagerAdapter {
	public ViewPagerAdapter(Activity activity, Views views[]) {
		this.views = views;// new Views[2];
		// views[0] = new NavigationPage(activity);
		// views[1] = new myDynamic(activity);
		// views[2] = new Microblogs(activity);
	}

	@Override
	public int getCount() {
		return views.length;
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
		return view == object;
	}

	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		View view = views[position].getActiveView();
		((ViewPager) container).addView(view, 0);
		return view;
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		((ViewPager) container).removeView(views[position].getActiveView());
	}

	public boolean back(int position) {
		return views[position].removeView();
	}

	public View getView(int position) {
		return views[position].getActiveView();
	}
	
	public Views getViews(int position){
		return views[position];
	}

	public void onReceive(SmsMessage msg) {
		// MessageItem msgitem = new MessageItem();
		//
		// msgitem.address = msg.getOriginatingAddress();
		// msgitem.person = null;
		// msgitem.date = msg.getTimestampMillis();
		// msgitem.protocol = 0;
		// msgitem.read = 0;
		// msgitem.status = -1;
		// msgitem.type = 1;
		// msgitem.body = msg.getMessageBody();
		//
		// ((Messages)views[1]).onReceive(msgitem);
	}

	private Views[] views;
}
